function preparray1() {
$.post("incphp/show_array.php", { posx: "123", posy: "456" } );
}


function ConfirmChoice(gstr)
{
answer = confirm("save?")
	if (answer !=0)
	{
		location = gstr;
	}
}

function preparray2(project_id)  { //lengthArray holds the length of markerArray
	//var gstr = '<a href="incphp/update_markers.php?project_id='+project_id+'&';
	//var gstr2 = 'incphp/update_markers.php?project_id='+project_id+'&';
	var gstr2 = 'ed04.php?project_id='+project_id+'&';
	for (i=0;i<lengthArray ;i++ )  {
	var id = markerArray[i][1]; //the stored ident
	var markerx = markerArray[i][2];
	var markery = markerArray[i][3];
	//gstr = gstr+'ident'+i+'='+id+'&x'+i+'='+markerx+'&y'+i+'='+markery+'&';
	gstr2 = gstr2+'ident'+i+'='+id+'&x'+i+'='+markerx+'&y'+i+'='+markery+'&';
	//str1 = (str1 + 'posx'+i+': "'+markerx+'", '+'posy'+i+': "'+markery+'", ');
	
	} //for
	//gstr = gstr+'">click</a>';
	//gstr = '<a href="incphp/show_array.php?project_id=23">click</a>';
	//$('#header').append(gstr); //*****************this
	ConfirmChoice(gstr2);
	//$.post("incphp/show_array.php", { posx: markerx, posy: markery} );
	//str2 = '{ posx0: "100", posy0: "200", posx1: "393", posy1: "364"}';
	//var str2 = '{ posx: "123", posy: "456" }';
	//$('#header').append(str2);
	//$.post("incphp/show_array.php", { strx: markerx, stry: markery} );
}

//set popup Status
var popupStatus=0;
var markerArray = new Array();
var lengthArray = 0; //arraylength
var edit = 1;

$(document).ready(function(){
//set background
//$('#map_canvas').css("backgroundColor","red");
//$("#map_canvas").css({"background-image":"url('upload/fgate2.JPG')"}); 
bg();



// function adds a marker, makes draggable and implements drag stop fn to update the array of markers
//if marker is existing it has numeric ident otherwise has been created after array was read as "mark"+i
function addmarker(ident,x,y,icon) {//mkid is the database identifier for the marker
		var style = (' style="position:absolute; left:'+ x +'px;top:'+ y +'px;" ');
		//var im = ('<img id="'+ident+'" class="mark" src="'+icon+'" width="'+iwidth+'" height="'+iheight+'"'+ style +' />');
		var im = ('<img id="'+ident+'" class="mark" src="upload/marker.png" width="20" height="34"'+ style +' />');
		//$('#side_panel').append('<p id="' +ident+ '">'+ident+' ' + x +', '+ y + '<p/>');
		$('#map_canvas').append(im);
		//var hash = ('#'+ident);
		var hash = ('.mark');
		// Make Draggable (edit mode)
			$(hash).draggable({
			stop: function(event, ui) {
				var ident = $(this).attr("id");
				//console.log("drag stop triggered event " + ident);
				var n = ident.slice(4); //Now undefined if ident is already existing
				var position = $(this).position();
				var l = position.left;
				var t = position.top ;
		//alert("clicked " + n + " left" + l + " top " + t);
		//$("p[id=" + ident + "]").html('<p id="' +ident+ '">'+ident+' ' + l +', '+ t + '<p/>'); //updates the side_panel display
		markerArray[n][2] = l; //new dragged values into array but n not defined
		markerArray[n][3] = t;  
		//console.log (markerArray[n][2]);
		//console.log (markerArray[n][3]);
			} //stop:  
	}); //draggable
} //fn


 
// gets json file with marker information and passes to an array

	  $.each(myobj.markers.marker, function(i, item) { //reads existing markers in myobj put in ed04.php from get_markers.php
				var ident='mark'+i;		//assign local ident
				var mkid= item.ident;	//pulled from the stored object
				var posx = item.posx;
				var posy = item.posy;
				var icon = "src";//not used yet
				markerPoint = new Array(ident, mkid, posx, posy, icon); //create marker element for array
				lengthArray = markerArray.push(markerPoint);//push onto array
				//console.log(ident, mkid, posx, posy, icon);
				addmarker(ident, posx, posy, icon);
		}); //.each

//  binds to a click on the map canvas to add markers
	$('#map_canvas')
		.bind('click',function(ev){
		i = lengthArray;
		var ident = ('mark' + i);
		var posx = ev.pageX - this.offsetLeft;
		var posy = ev.pageY - this.offsetTop;
		var icon = "src";//not used yet
		markerPoint = new Array(ident, ident, posx, posy, icon); //create marker element for array
		lengthArray = markerArray.push(markerPoint);				//push onto array
		addmarker(ident,posx,posy,icon);		//mkid for a new marker is same as the ident for the page
		//console.log(ident,posx, posy, icon);
	});  //bind
/*
// test event handler to print arra contents
	$('#footer')
		.bind('click',function(ev){
		for (i=0;i<lengthArray;i++) //
			{ 
			$('#side_panel').append(markerArray[i][0] + ' ' + markerArray[i][1] + ' ' + markerArray[i][2] + '<br />');
			}
		}); //bind
		// test event handler to print arra contents
	$('#header')
		.bind('click',function(ev){
				edit = 0;
				console.log("edit is " + edit);
		}); //bind
*/


}); //document ready